<?php

namespace app\api\service;

use app\model\AgentFinanceDaily;
use app\model\FinanceDaily;

class DailyFinance extends CommonService
{
    /*
     $dateTime 为 2021-11-11 11:11:11格式
    */
    public function increase($agentId, $dateTime, $income, $agentProfit, $profit)
    {
        $dateymd = substr($dateTime, 0, 10);
        $res = (new AgentFinanceDaily())->increase($agentId, $dateymd, $income, $income - $agentProfit, $agentProfit);
        if (!$res) {
            return $this->inValiReturn('同步代理商财务日报失败');
        }
        $res = (new FinanceDaily())->increase($dateymd, $income, $income - $profit, $profit);
        if (!$res) {
            return $this->inValiReturn('同步代财务日报失败');
        }

        return $this->valiReturn();
    }

    /*
     $dateTime 为 2021-11-11 11:11:11格式
    */
    public function decrease($agentId, $dateTime, $income, $agentProfit, $profit)
    {
        $dateymd = substr($dateTime, 0, 10);
        $res = (new AgentFinanceDaily())->decrease($agentId, $dateymd, $income, $income - $agentProfit, $profit);
        if (!$res) {
            return $this->inValiReturn('同步代理商财务日报失败');
        }
        $res = (new FinanceDaily())->decrease($dateymd, $income, $income - $agentProfit, $profit);
        if (!$res) {
            return $this->inValiReturn('同步代理商财务日报失败');
        }

        return $this->valiReturn();
    }
}
